﻿#include "CPdfRptInterface.h"
#include "CPdfRptDataPkg.h"
#include "CGlobal.h"
#include "CPdfRptBase.h"
#include "CPoolTaskRpt.h"

CPdfRptInterface::CPdfRptInterface(QObject *parent)
	: QObject(parent)
{
	m_pThreadPool = new QThreadPool();//new 线程池
	m_pThreadPool->setMaxThreadCount(1);//最大线程数设置1,按顺序执行输出
	//new数据组包类
	m_pPdfRptDataPkg = new CPdfRptDataPkg();
	m_pRptBase = new CPdfRptBase();
}

CPdfRptInterface::~CPdfRptInterface()
{
	if (m_pThreadPool != nullptr)
	{
		m_pThreadPool->waitForDone();//等待所有任务完成后再销毁

		SAFE_DELETE(m_pThreadPool);
	}
	
	SAFE_DELETE(m_pPdfRptDataPkg);
	SAFE_DELETE(m_pRptBase);
}

void CPdfRptInterface::expCorrectPdfRpt(QString sPdfFolderPath, QString sHttpPrefix, QString sClientCpyName, QDateTime dStartTime, QDateTime dEndTime)
{
	if (m_pPdfRptDataPkg == nullptr || m_pThreadPool == nullptr)
	{
		return;
	}

	//首先先组包
	QString sErrMsg = "";
	CAllPdfRptDataInfo dataInfo;//数据合集
	m_pPdfRptDataPkg->pkgRestPdfRptData(dStartTime, dEndTime, sPdfFolderPath, sHttpPrefix, dataInfo, sErrMsg);//使用组包类-->组包其他AI检测数据
	//导出AI检测报表(扔进线程池)
	CPoolTaskRpt *pPoolTaskRestRpt = new CPoolTaskRpt();//创建任务类对象(内部执行完自动delete)
	pPoolTaskRestRpt->setData(dataInfo.rectifyDataInfo, m_pRptBase);
	m_pThreadPool->start(pPoolTaskRestRpt);
}

